package cn.wolfcode.utils;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.InputStream;

public class MybatisUtil {
    private MybatisUtil(){}
    private static SqlSessionFactory fac;
    static {
        try {
            InputStream in= Resources.getResourceAsStream("mybatis-config.xml");
            //获取连接
            fac = new SqlSessionFactoryBuilder().build(in);
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    public static SqlSession openSession(){
        return fac.openSession();
    }
}
